package com.ben.multiple.message.biz.model;

import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @author BenJin Yin
 * @date 2020/7/23
 */
@Data
public class MessageResult implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 自定义响应状态、状态描述；只是通信状态
     */
    private String status;
    private String remark;
    /**
     * 唯一请求 ID
     */
    private String requestId;
    /**
     * 响应详情
     */
    private List<ResultDetail> resultDetailList;

    public MessageResult(String status, String remark) {
        this.status = status;
        this.remark = remark;
    }

    public static MessageResult success() {
        return new MessageResult(StatusEnum.SUCCESS.getStatus(), StatusEnum.SUCCESS.getRemark());
    }

    public static MessageResult error(String msg) {
        String remark = (msg != null && !"".equals(msg)) ? msg : StatusEnum.ERROR.getRemark();
        return new MessageResult(StatusEnum.ERROR.getStatus(), remark);
    }

    public enum StatusEnum {
        /**
         * 响应状态码
         */
        SUCCESS("0000", "操作成功"),
        ERROR("9999", "操作失败");
        private final String status;
        private final String remark;

        StatusEnum(String status, String remark) {
            this.status = status;
            this.remark = remark;
        }

        public String getStatus() {
            return status;
        }

        public String getRemark() {
            return remark;
        }
    }

    /**
     * 响应详情
     */
    @Data
    public static class ResultDetail implements Serializable {
        private static final long serialVersionUID = 1L;
        /**
         * 发送流水号
         */
        private String serialNo;
        /**
         * 手机号码
         */
        private String phoneNumber;
        /**
         * 计费条数
         */
        private Long fee;
        /**
         * 短信请求错误码，具体含义请参考错误码   Ok：成功
         */
        private String code;
        /**
         * 短信请求错误码描述
         */
        private String message;
    }
}
